package wiki;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.Map;

import com.Root;

public class GetDetails {
	
	public Map<String, String> GetIssueDetail(String issueid) {
		Root root = new Root();
		ResultSet rs = null;
		PreparedStatement pst = null;
		String sql = "";
		String sql1 = "";
		ResultSet rs1 = null;
		PreparedStatement pst1 = null;

		Map<String, String> details = new HashMap<String, String>();

		//System.out.println("Issueid: : " + issueid);

		try {
			root.initConnection();

			sql = "Select id, issuetitle, issuedetails, moduleid, categoryid, subcategoryid, module, category, subcategory, bugid,issueidforuser, version, createdby, createdon from issue where id= ? ";
			pst = root.con.prepareStatement(sql);
			pst.setString(1, issueid);
			rs = pst.executeQuery();

			//System.out.println("PST: " + pst);
			rs.next();

			details.put("Issueid", rs.getString("id"));
			details.put("Title", rs.getString("issuetitle"));
			details.put("Details", rs.getString("issuedetails"));

			details.put("Moduleid", rs.getString("moduleid"));
			details.put("Categoryid", rs.getString("categoryid"));
			details.put("SubCategoryid", rs.getString("subcategoryid"));

			details.put("Module", rs.getString("module"));
			details.put("Category", rs.getString("category"));
			details.put("SubCategory", rs.getString("subcategory"));

			details.put("Bugid", rs.getString("bugid"));
			details.put("Issueidforuser", rs.getString("issueidforuser"));
			details.put("Version", rs.getString("version"));
			details.put("CreatedBy", rs.getString("createdby"));
			details.put("CreatedOn", rs.getString("createdon"));

			sql1 = "Select count(*) as count from issuedetails where issueid= ? and deleteflag=0 ";
			pst1 = root.con.prepareStatement(sql1);
			pst1.setString(1, issueid);
			rs1 = pst1.executeQuery();

			//System.out.println(pst1);
			rs1.next();
			details.put("CommentCount", rs1.getString("count"));

			// System.out.println("Version: " + rs.getString("version"));

		} catch (Exception e) {
			System.out.println("Error reading issue details " + e.toString());
		} finally {
			try {
				rs.close();
				pst.close();
				rs1.close();
				pst1.close();
				root.closeConnection();
			} catch (Exception e) {

			}

		}
		return (details);
	}

}
